import 'dart:convert';

import 'package:C20Driver/utils/toast.dart';
import 'package:encrypt/encrypt.dart';


import 'encrypt.dart';

class EncryptData {
  ///Aes解密
  static Future<dynamic> decryptHttpData(dynamic res) async {

    var signKey = res['signKeys'];
    print("weeee_$signKey");
    var dataRes = res['data'];
    print("weeee_$dataRes");
    var sign = await Encrypt.decrypt(Encrypted.fromBase64(signKey).base64);
    print("weeee_$sign");
    var aesKey = jsonDecode(sign);
    var key = aesKey['aesKey'];
    var time=aesKey['time'];
    var now=DateTime.now().millisecondsSinceEpoch~/1000;
    if(time-now>300){
      ToastX.center("请稍后重试");
      return null;
    }
    var dat = Encrypt.decryptAes(key, dataRes);

    var data = jsonDecode(dat);
    print("weeee_$data");
    return data;
  }
}
